<template>
  <div class="parentbox">
    <Parent :parentData="parentData.parent" v-if="parentData.parent" />
    <div class="userinfo">
      <div class="info">
        <span class="author">{{ parentData.user.nickname }} </span>
        <span class="date">2小时前</span>
      </div>
      <div class="huifu" @click="sendComment">回复</div>
    </div>
    <div class="content">{{ parentData.content }}</div>
  </div>
</template>

<script>
import eventBus from "../../utils/eventBus";
export default {
  //子组件（父评论）自己给自己添加的递归name！！
  name: "Parent",
  props: ["parentData"],
  methods: {
    //回复楼层中的父评论
    sendComment() {
      // eventBus.$on(this.sendMsg);    错误呀！！
      eventBus.$emit(
        "sendMsg",
        this.parentData.id,
        this.parentData.user.nickname
      );
    },
  },
};
</script>

<style lang="less" scoped>
.parentbox {
  padding: 2px;
  margin: 5px;
  border: 1px solid #888;
  .userinfo {
    display: flex;
    align-items: center;
    // margin-bottom: 6 / 360 * 100vw;
    .info {
      flex-grow: 1;
      .author {
        color: #333;
        font-size: 16 / 360 * 100vw;
      }
      .date {
        padding-left: 10 / 360 * 100vw;
        color: #888;
        font-size: 14 / 360 * 100vw;
      }
    }
    .huifu {
      color: #888;
      font-size: 14 / 360 * 100vw;
    }
  }
  .content {
    // margin-top: 3 / 360 * 100vw;
    padding: 10 / 360 * 100vw;
    color: #333;
    font-size: 16 / 360 * 100vw;
    // 当评论输入过长时：可以用word-break：break-all断行
    word-break: break-all;
    text-indent: 20px;
  }
}
</style>